#include "cXmlHelper.h"
#include "Plugins/xmlHelper/pugixml.hpp"
bool Tool_parseDeviceXML(const char* xmlString, std::map<std::string, std::string>& mapResult)
{
    if(NULL == xmlString || xmlString[0] == '\0')
        return false;

    pugi::xml_document doc;
    pugi::xml_parse_result  result = doc.load_string(xmlString);
    // std::cout << "Load result: " << result.description() << std::endl;

    pugi::xml_node ResultNode = doc.child("HvcResultDoc").child("ResultSet").child("Result");
    if (!ResultNode)
    {
       // std::cout << "no find Result.\n";
       return false;
    }

    for (pugi::xml_node iter = ResultNode.first_child(); iter != NULL; iter = iter.next_sibling())
    {
        //if (!iter.text().empty())
        //{
        //    std::cout << "text: " << iter.text().as_string() << std::endl;
        //}
        //std::cout << "name: " << iter.name() << std::endl;
        ////std::cout << "value: " << iter.value() << std::endl;
        //std::cout << "attribute value: " << iter.attribute("value").value() << std::endl;
        //std::cout << "\n";

        if (!iter.text().empty())
        {
            mapResult[iter.name()] = iter.text().as_string();
        }
        else if(!iter.attribute("value").empty())
        {
            mapResult[iter.name()] = iter.attribute("value").value();
        }
    }
    return true;
}
